// ignore_for_file: constant_identifier_names

import 'dart:convert';

import 'package:dio/dio.dart';

enum Method { get, post, delete, put, patch, head }

const MethodValues = {
  Method.get: "get",
  Method.post: "post",
  Method.delete: "delete",
  Method.put: "put",
  Method.patch: "patch",
  Method.head: "head",
};

class Result {
  int? statusCode;
  String? statusMessage;
  dynamic data;

  Result();

  // from json
  factory Result.fromJson(Response response) {
    return Result()
      ..statusCode = response.statusCode
      ..statusMessage = response.statusMessage
      ..data = response.data;
  }

  // to json
  Map<String, dynamic> toJson() {
    return {
      'code': statusCode,
      'errorMsg': statusMessage,
      'data': data,
    };
  }

  @override
  String toString() {
    return jsonEncode(this);
  }

  // 404，对话不存在
  // 400，invalid_param，传入参数异常
  // 400，app_unavailable，App 配置不可用
  // 400，provider_not_initialize，无可用模型凭据配置
  // 400，provider_quota_exceeded，模型调用额度不足
  // 400，model_currently_not_support，当前模型不可用
  // 400，completion_request_error，文本生成失败
  // 500，服务内部异常
  static bool isSuccess(int code) {
    return code >= 200 && code < 300;
  }
}
